package com.demo.controller;


import java.util.List;

import com.demo.annotation.GlobalInterceptor;
import com.demo.entity.constants.Constants;
import com.demo.entity.dto.SessionWebUserDto;
import com.demo.entity.po.ChatMessage;

import com.demo.entity.query.ChatMessageQuery;

import com.demo.entity.vo.PaginationResultVO;

import com.demo.entity.vo.ResponseVO;

import org.aspectj.apache.bcel.classfile.Constant;
import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import com.demo.service.ChatMessageService;

/**
 * @Description:聊天消息表Controller
 * @Date:2025-03-09
 * @author：author
*/
@RestController
@RequestMapping("/chat")
public class ChatMessageController extends ABaseController {

	@Resource
	private ChatMessageService chatMessageService;

	/**
	 * 分页查询
	 */
	@RequestMapping("/loadMessageList")
	@GlobalInterceptor
	public ResponseVO loadDataList(ChatMessageQuery query){
		query.setOrderBy("send_time");
		List<ChatMessage> chatMessages = chatMessageService.findListByParam(query);
		return getSuccessResponseVO(chatMessages);
	}

	/**
	 * 发送消息
	 */
	@RequestMapping("/sendMessage")
	@GlobalInterceptor
	public ResponseVO add(HttpSession session, ChatMessage bean) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		bean.setSendUserId(String.valueOf(webUserDto.getUserId()));
		bean.setSessionId("1");
		bean.setMessageType(Constants.ZERO);
		this.chatMessageService.sendMessage(bean);
		return getSuccessResponseVO(null);
	}
}